﻿using FFMpegCore;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace SignalRvideo
{
    public class FFmpegPushService : BackgroundService
    {
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return Task.Factory.StartNew(async () => { await FFmpegPush(stoppingToken); }, TaskCreationOptions.LongRunning);
        }

        private async Task FFmpegPush(CancellationToken stoppingToken)
        {
            var arguments = FFMpegArguments.FromInputFiles(@"D:/ffmpeg/bin/testst1.mp4")
                .ForceFormat("mpegts")
                .Scale(320, 240)
                .WithVideoCodec("mpeg1video")
                .WithAudioCodec("mp2");
            var processor = arguments.OutputToFile("http://127.0.0.1:5000/home/Upts").CancellableThrough(out var cancel);
            processor.ProcessSynchronously(false);
        }
    }
}
